home *** CD-ROM | disk | FTP | other *** search
/ Fifty: Elektronik / FIFTY Elektronik (PS_Computer_Vertrieb).iso / ps8 / fty1017 / gepackt.exe / DISK2 / PLOTSRC.EXE / EMS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-11-10  |  5.0 KB  |  163 lines

  1. UNIT EMS;
  2. (***************************************************************************)
  3. (* Expanded Memory Unit für Turbo Pascal 6.0                               *)
  4. (* (c) vorerst keines                                                      *)
  5. (* 1990, Reebear in : E.,M.,S. - Turbo 6.0 & Vision                        *)
  6. (***************************************************************************)
  7.  
  8. INTERFACE
  9.  
  10. VAR
  11.   EMMError : BYTE;
  12.  
  13. FUNCTION GetVersion : String;
  14.  
  15. FUNCTION EMMErrorMsg (ErrorCode : INTEGER): String;
  16.  
  17. FUNCTION TestEMMDriver : BOOLEAN;
  18.  
  19. PROCEDURE GetPageFrameAddr (VAR PageFrameSeg: WORD);
  20.  
  21. PROCEDURE EMMPageCount (VAR PagesAvail, PagesTotal: WORD);
  22.  
  23. FUNCTION AllocatePages (Pages: WORD): WORD;
  24.  
  25. PROCEDURE EMMPageMap (PhysPage: BYTE; LogPage, EMMHandle: WORD);
  26.  
  27. PROCEDURE ReleasePage (EMMHandle: WORD);
  28.  
  29.  
  30. IMPLEMENTATION
  31.  
  32. USES DOS;
  33.  
  34. CONST
  35.   EMMIntr : WORD = $67;
  36.  
  37. VAR
  38.   Regs : Registers;
  39.  
  40. PROCEDURE CallEMM (VAR Regs : Registers);
  41. BEGIN
  42.   Intr (EMMIntr, Regs);
  43.   EMMError := Regs.AH;
  44. END;
  45.  
  46. FUNCTION EMMErrorMsg (ErrorCode : INTEGER): String;
  47. BEGIN
  48.   CASE ErrorCode OF
  49.     $00 : EMMErrorMsg := 'No error';
  50.     $80 : EMMErrorMsg := 'Internal error in EMM software';
  51.     $81 : EMMErrorMsg := 'Malfunction in EMS hardware';
  52.     $82 : EMMErrorMsg := 'Memory manager busy';
  53.     $83 : EMMErrorMsg := 'Invalid handle';
  54.     $84 : EMMErrorMsg := 'Function not defined';
  55.     $85 : EMMErrorMsg := 'Handles exhausted';
  56.     $86 : EMMErrorMsg := 'Error in save or restore of mapping context';
  57.     $87 : EMMErrorMsg := 'Not enough pages physically available';
  58.     $88 : EMMErrorMsg := 'Not enough pages currently available';
  59.     $89 : EMMErrorMsg := 'Zero pages cannot be allocated';
  60.     $8A : EMMErrorMsg := 'Requested logical page is outside of pages owned by handle';
  61.     $8B : EMMErrorMsg := 'Illegal physical page number in mapping request';
  62.     $8C : EMMErrorMsg := 'Page mapping hardware-state save area is full';
  63.     $8D : EMMErrorMsg := 'Mapping context save failed';
  64.     $8E : EMMErrorMsg := 'Mapping context restore failed';
  65.     $8F : EMMErrorMsg := 'Subfunction parameter not defined';
  66.     $90 : EMMErrorMsg := 'Attribute type not defined';
  67.     $91 : EMMErrorMsg := 'Feature not supported';
  68.     $92 : EMMErrorMsg := 'Memory regions overlap - move was performed, part of source region overwritten';
  69.     $93 : EMMErrorMsg := 'Specified length is longer than actual length';
  70.     $94 : EMMErrorMsg := 'Conventional and expanded memory regions overlap';
  71.     $95 : EMMErrorMsg := 'Specified offset is outside logical page';
  72.     $96 : EMMErrorMsg := 'Region length exceeds 1 MByte';
  73.     $97 : EMMErrorMsg := 'Memory regions overlap - exchange not performed';
  74.     $98 : EMMErrorMsg := 'Memory source and destination types are undefined';
  75.     $99 : EMMErrorMsg := 'Error code currently unused';
  76.     $9A : EMMErrorMsg := 'Specified alternate register set is not supported';
  77.     $9B : EMMErrorMsg := 'All alternate register sets are currently allocated';
  78.     $9C : EMMErrorMsg := 'Alternate map or DMA register not supported  but register set is not zero';
  79.     $9D : EMMErrorMsg := 'Alternate register set not defined or not allocated';
  80.     $9E : EMMErrorMsg := 'Dedicated DMA channels are not supported';
  81.     $9F : EMMErrorMsg := 'Specified DMA channel is not supported';
  82.     $A0 : EMMErrorMsg := 'No handle found for specified name';
  83.     $A1 : EMMErrorMsg := 'Handle with same name already exists';
  84.     $A3 : EMMErrorMsg := 'Invalid pointer passed to function, or contents of source array corrupted';
  85.     $A4 : EMMErrorMsg := 'Access to function denied by DOS';
  86.     ELSE  EMMErrorMsg := 'Unknown error code';
  87.   END;
  88. END;
  89.  
  90. FUNCTION TestEMMDriver : BOOLEAN;
  91. TYPE  IDType = ARRAY [1..8] OF CHAR;
  92.  
  93. CONST ID     : IDType = 'EMMXXXX0';
  94.  
  95. Var P :Pointer;
  96.  
  97.  
  98. BEGIN
  99.   EMMerror:=$FF;
  100.   TestEMMDriver:=false;
  101.   GetIntVec(EMMIntr,P);
  102.   If P=nil then Exit;
  103.   If Not (ID = IDType(Ptr(Seg(P^), 10)^)) then Exit;
  104.   Regs.AH := $40;
  105.   CallEMM (Regs);
  106.   TestEMMDriver := (Regs.AH = 0);
  107. END;
  108.  
  109.  
  110. PROCEDURE GetPageFrameAddr (VAR PageFrameSeg: WORD);
  111. BEGIN
  112.   Regs.AH := $41;
  113.   CallEMM (Regs);
  114.   PageFrameSeg := Regs.BX;
  115. END;
  116.  
  117. PROCEDURE EMMPageCount (VAR PagesAvail, PagesTotal: WORD);
  118. BEGIN
  119.   Regs.AH := $42;
  120.   CallEMM (Regs);
  121.   EMMError := Regs.AH;
  122.   PagesAvail := Regs.BX;
  123.   PagesTotal := Regs.DX;
  124. END;
  125.  
  126. FUNCTION AllocatePages (Pages: WORD): WORD;
  127. BEGIN
  128.   Regs.AH := $43;
  129.   Regs.BX := Pages;
  130.   CallEMM (Regs);
  131.   AllocatePages := Regs.DX;
  132. END;
  133.  
  134. PROCEDURE EMMPageMap (PhysPage: BYTE; LogPage, EMMHandle: WORD);
  135. BEGIN
  136.   Regs.AH := $44;
  137.   Regs.AL := PhysPage;
  138.   Regs.BX := LogPage;
  139.   Regs.DX := EMMHandle;
  140.   CallEMM (Regs);
  141.   EMMError := Regs.AH;
  142. END;
  143.  
  144. PROCEDURE ReleasePage (EMMHandle: WORD);
  145. BEGIN
  146.   Regs.AH := $45;
  147.   Regs.DX := EMMHandle;
  148.   CallEMM (Regs);
  149. END;
  150.  
  151. FUNCTION GetVersion : String;
  152. VAR
  153.   VersionStr : String;
  154.   VersionBCD : BYTE;
  155. BEGIN
  156.   Regs.AH := $46;
  157.   CallEMM (Regs);
  158.   VersionBCD := Regs.AL;
  159.   VersionStr := CHR((VersionBCD DIV 16)+48) + '.' + CHR((VersionBCD MOD 16)+48);
  160.   GetVersion := VersionStr;
  161. END;
  162.  
  163. END.